package com.group.elmboot.controller;

import com.group.elmboot.po.CreditTransaction;
import com.group.elmboot.po.RedPacket;
import com.group.elmboot.service.CreditService;
import com.group.elmboot.vo.CreditTransactionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RefreshScope//开启动态刷新
@RestController
@RequestMapping("/CreditController")
public class CreditController {

    @Autowired
    private CreditService creditService;

    @GetMapping("/earnCredit")
    public int earnCredit(CreditTransactionVO creditTransactionVO) throws Exception {
        return creditService.earnCredit(creditTransactionVO);
    }

    @GetMapping("/consumeCredit")
    public int consumeCredit(CreditTransactionVO creditTransactionVO) throws Exception {
        return creditService.consumeCredit(creditTransactionVO);
    }

    @GetMapping("/getCreditById/{userId}")
    public int getCreditById(@PathVariable String userId){
        return creditService.getCreditById(userId);
    }

    @GetMapping("/listCreditTransactionByPage/{userId}/{current}/{size}")
    public List<CreditTransaction> listCreditTransactionByPage(@PathVariable String userId, @PathVariable int current, @PathVariable int size){
        return creditService.listCreditTransactionByPage(userId,current,size);
    }

    @GetMapping("/listCreditEarnTransactionByPage/{userId}/{current}/{size}")
    public List<CreditTransaction> listCreditEarnTransactionByPage(@PathVariable String userId,@PathVariable int current,@PathVariable int size){
        return creditService.listCreditEarnTransactionByPage(userId,current,size);
    }

    @GetMapping("/listCreditConsumeTransactionByPage/{userId}/{current}/{size}")
    public List<CreditTransaction> listCreditConsumeTransactionByPage(@PathVariable String userId,@PathVariable int current,@PathVariable int size){
        return creditService.listCreditConsumeTransactionByPage(userId,current,size);
    }

    @GetMapping("/listAllRedPackets/{userId}/{current}/{size}")
    public List<RedPacket> listAllRedPackets(@PathVariable String userId,@PathVariable int current,@PathVariable int size){
        return creditService.listAllRedPackets(userId,current,size);
    }

    @GetMapping("listAvailableRedPackets/{userId}/{current}/{size}")
    public List<RedPacket> listAvailableRedPackets(@PathVariable String userId,@PathVariable int current,@PathVariable int size){
        return creditService.listAvailableRedPackets(userId,current,size);
    }

    @GetMapping("listUsedRedPackets/{userId}/{current}/{size}")
    public List<RedPacket> listUsedRedPackets(@PathVariable String userId,@PathVariable int current,@PathVariable int size){
        return creditService.listUsedRedPackets(userId,current,size);
    }

    @GetMapping("getAvailableRedPacketCategory/{userId}")
    public int getAvailableRedPacketCategory(@PathVariable String userId){
        return creditService.getAvailableRedPacketCategory(userId);
    }

    @GetMapping("redPacketUse/{userId}/{amount}/{orderId}")
    public int redPacketUse(@PathVariable String userId,@PathVariable int amount,@PathVariable int orderId){
        return creditService.redPacketUse(userId,amount,orderId);
    }

    @GetMapping("listAllUsedRedPackets/{userId}")
    public List<RedPacket> listAllUsedRedPackets(@PathVariable String userId){
        return creditService.listAllUsedRedPackets(userId);
    }
}
